package com.gxy.learn.design.model.create.prototype.deepclone;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @description: 原形模式测试类-深拷贝
 * @author: gaoxueyong
 * @Date: 2022/11/7 11:58
 */
@Slf4j
public class Client {
    public static void main(String[] args) throws Exception {

        Citation citation = new Citation();
        Student student = new Student();
        student.setName("张三");
        citation.setStudent(student);


//        开始深克隆
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("/Users/gaoxueyong/Desktop/citation.java"));
        oos.writeObject(citation);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("/Users/gaoxueyong/Desktop/citation.java"));
        Citation citation1 = (Citation) ois.readObject();
        ois.close();
        citation1.getStudent().setName("李四");
        citation.show();
        citation1.show();
        citation.show();


    }
}
